﻿
/*
 * Copyright (C) 2011  Roy Sanchez
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 * 
 * 
 * +
 * if you find any bug or just have a question, can email me.
 * email : roygold8@gmail.com
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FTP_Client
{
    public class File_Info : IEqualityComparer<File_Info>, IEquatable<File_Info>, IComparable<File_Info>
    {

        #region Variables

        string Rights = string.Empty;
        string Owner = string.Empty;
        string Group = string.Empty; 
        string Date = string.Empty;
        string Time = string.Empty;
        string Path = string.Empty;
        string Name;
        public bool isFolder = false;
        public bool isFile = false;
        int Link = 0;
        long Size = 0;

        DateTime Fecha = DateTime.Now;

        #endregion Variables

        #region Metodos

        public string getRights()
        {
            return Rights;
        }

        public string getOwner()
        {
            return Owner;
        }

        public string getGroup()
        {
            return Group;
        }


        public string getPath()
        {
            return Path;
        }

        public string getName()
        {
            return Name;
        }

        public DateTime getDate()
        {
            return Fecha;
        }

        public int getLink()
        {
            return Link;
        }

        public long getSize()
        {
            return Size;
        }


        public void setRights(string _Rights)
        {
            Rights = _Rights;
        }

        public void setOwner(string _Owner)
        {
            Owner = _Owner;
        }

        public void setGroup(string _Group)
        {
            Group = _Group;
        }

        public void setName(string _Name)
        {
            Name = _Name;
        }

        public void setPath(string _Path)
        {
            Path = _Path;
        }

        public void setDate(DateTime _Date)
        {
            Fecha = _Date;
        }

        public void setLink(int _Link)
        {
            Link = _Link;
        }

        public void setSize(long _Size)
        {
            Size = _Size;
        }

        #endregion Metodos

        public File_Info()
        {
        }

        public File_Info(string _Rights, string _Owner, string _Group, string _Name, int _Link, int _Size)
        {
            Rights = _Rights;
            Owner = _Owner;
            Group = _Group;
            Path = _Name;
            Link = _Link;
            Size = _Size;
        }

        public File_Info(string _Rights, string _Owner, string _Group, string _Name, int _Link, int _Size, string _Date, string _Time)
        {
            Rights = _Rights;
            Owner = _Owner;
            Group = _Group;
            Path = _Name;
            Link = _Link;
            Size = _Size;
            Date = _Date;
            Time = _Time;
        }

        public File_Info(string _Rights, string _Owner, string _Group, string _Name, int _Link, int _Size, DateTime _Date)
        {
            Rights = _Rights;
            Owner = _Owner;
            Group = _Group;
            Path = _Name;
            Link = _Link;
            Size = _Size;
            Fecha = _Date;
        }




        public bool Equals(File_Info x, File_Info y)
        {
            if (x.getRights() != y.getRights())
                return false;
            if (x.getLink() != y.getLink())
                return false;
            if (x.getOwner() != y.getOwner())
                return false;
            if (x.getGroup() != y.getGroup())
                return false;
            if (x.getSize() != y.getSize())
                return false;
            /*
            if (x.getDateString() != y.getDateString())
                return false;
            
            if (x.getTimeString() != y.getTimeString())
                return false;
            */
            if (x.getDate() != y.getDate())
                return false;
            if (x.getPath() != y.getPath())
                return false;
            if (x.GetHashCode() != y.GetHashCode())
                return false;

            return true;
        }

        public int GetHashCode(File_Info obj)
        {
            return obj.GetHashCode();
        }


        public override int GetHashCode()
        {
            int Hashcode = Rights.GetHashCode() + Link.GetHashCode() + Group.GetHashCode()
                + Size.GetHashCode();
            Hashcode = Hashcode ^ 8;

            return Hashcode;
        }

        public int CompareTo(File_Info other)
        {
            if (this.Equals(other))
                return 0;

            int este = 0, otro = 0;


            if (this.getRights() != string.Empty)
                este += 2;
            if (other.getRights() != string.Empty)
                otro += 2;


            if (this.getLink() != 0)
                este += 1;
            if (other.getLink() != 0)
                otro += 1;


            if (this.getOwner() != string.Empty)
                este += 1;
            if (other.getOwner() != string.Empty)
                otro += 1;

            if (this.getGroup() != string.Empty)
                este += 1;
            if (other.getGroup() != string.Empty)
                otro += 1;

            if (this.getSize() != 0)
                este += 2;
            if (other.getSize() != 0)
                otro += 2;


            if (this.getPath() != string.Empty)
                este += 2;
            if (other.getPath() != string.Empty)
                otro += 2;

            if (este > otro)
                return 1;
            else
                return -1;
        }

        public bool Equals(File_Info other)
        {
            return this.Equals(this, other);
        }
    }
}
